package com.xeecos
{
	import fl.controls.Button;
	import fl.controls.List;
	import fl.data.DataProvider;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	public class ListPanel extends Sprite
	{
		public var list_articles:List;
		public var btn_prev:Button;
		public var btn_next:Button;
		public var btn_add:Button;
		public var btn_refresh:Button;
		public function ListPanel()
		{
			super();
			btn_refresh.addEventListener(MouseEvent.CLICK,onRefresh);
			btn_prev.addEventListener(MouseEvent.CLICK,onPrevPage);
			btn_next.addEventListener(MouseEvent.CLICK,onNextPage);
			ArticlesManager.sharedManager.addEventListener(Event.COMPLETE,onComplete);
			list_articles.addEventListener(Event.CHANGE,onChange);
			list_articles.rowHeight = 44.0;
		}
		private function onComplete(evt:Event):void{
			var dataProvider:DataProvider = new DataProvider();
			for(var i:int =0;i<ArticlesManager.sharedManager.currentList.length;i++){
				dataProvider.addItem({label:ArticlesManager.sharedManager.currentList[i].id+":"+ArticlesManager.sharedManager.currentList[i].name,data:ArticlesManager.sharedManager.currentList[i].id})
			}
			list_articles.dataProvider = dataProvider;
		}
		private function onChange(evt:Event):void{
			ArticlePanel.sharedPanel.refresh(list_articles.selectedItem.data);
		}
		private function onRefresh(evt:MouseEvent):void{
			ArticlesManager.sharedManager.getLastestPage();
		}
		private function onPrevPage(evt:MouseEvent):void{
			ArticlesManager.sharedManager.getPrevPage();
		}
		private function onNextPage(evt:MouseEvent):void{
			ArticlesManager.sharedManager.getNextPage();
		}
	}
}